package com.ncdnapp.service;

import com.ncdnapp.core.exception.BussinessException;
import com.ncdnapp.core.thread.ThreadFactory;
import com.ncdnapp.core.tracer.TraceThread;
import com.ncdnapp.dao.CUserDao;
import com.ncdnapp.dao.UserDao;
import com.ncdnapp.dao.po.CUserPO;
import com.ncdnapp.dao.po.UserPO;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.data.annotation.Transaction;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;

import java.util.concurrent.ExecutorService;

@Component
@Slf4j
public class UserService {
    @Inject
    private CUserDao cUserDao;
    @Inject
    private UserDao userDao;
    @Inject
    private RedissonClient redissonClient;
    private ExecutorService executorService = ThreadFactory.getVirtualThreadPool("hello");
    @Transaction
    public void test() {
        RBucket<Object> a = redissonClient.getBucket("a", new StringCodec());

/*        CUserPO cUserPO = new CUserPO().setName("aaaaaa");
        cUserDao.insert(cUserPO);
        UserPO userPO = new UserPO().setName("bbbbbbbbbb");
        userDao.insert(userPO);*/
        TraceThread t1 = new TraceThread(() -> {
            log.info("heeeeeeeeeeeeeee");
            executorService.submit(new TraceThread(() -> {
                log.info("ffffffffffffffffffffffffff");
            }));
        });
        t1.setName("hello");
        //t1.start();
        executorService.submit(t1);
       // throw new BussinessException(10001, "error");
    }
}
